package com.sz.config;

import com.sz.config.intercepors.Index3Interceptor;
import com.sz.config.intercepors.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    @Resource
    private LoginInterceptor loginInterceptor;
    @Resource
    private Index3Interceptor index3Interceptor;

    /*
    * 配置静态资源
    * */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**")
                .addResourceLocations("/classpath:/templates/,classpath:/statics/");
    }

    /*
    * 配置拦截器
    * */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //界面1可直接访问
        registry.addInterceptor(loginInterceptor).addPathPatterns("/*").excludePathPatterns("/toIndex","/","/login/toRegister");
        //访问界面3需要1或0权限
        registry.addInterceptor(index3Interceptor).addPathPatterns("/toIndex3");
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("forward:/toIndex");
    }
}
